import java.util.Scanner;

public class DichotomyLookup {
    public static void main(String[] args) {
        int[]arry={1,2,3,4,5,6,7};
        Scanner scanner=new Scanner(System.in);
        System.out.print("请输入要查找的数：");
        int n= scanner.nextInt();
        int left=0;
        int right= arry.length-1;

        while(left<=right){
            int mid=(left+right)/2;
            if(n<arry[mid]){
                right=mid-1;
            }
            else if(n>arry[mid]){
                left=mid+1;

            }
            else {
                System.out.println("该数在数组中的下标为：" + mid);//n=arry[mid]的情况
                break;
            }
            }
        if(left>right){

            System.out.println("数组中没有该元素");}


        }



    }

